<template>
  <div class="point-balance views-container">
    <div class="wlm-form">
      <div class="wlm-form-hearder flex-row flex-justify-b">
        <span>余额设置</span>
      </div>
      <section>
        <div class="wlm-form-content">
          <el-form ref="aliyun" :model="formFormatData.formData.key" size="small" label-width="140px" class="retail-form" label-position="right">
            <el-form-item label="开启充值">
              <el-radio-group v-model="formFormatData.formData.balance.open">
                <el-radio label="2">关闭</el-radio>
                <el-radio label="1">开启</el-radio>
              </el-radio-group>
            </el-form-item>
            
            <el-form-item label="文字定义">
              <el-input placeholder="余额" v-model="formFormatData.formData.balance.str">
              </el-input>
            </el-form-item>
            <el-form-item label="退款至余额总设置">
              <el-radio-group v-model="formFormatData.formData.balance.is_refund_balance ">
                <el-radio label="1">退款至余额</el-radio>
                <el-radio label="2">原路返回</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="退款免审核">
              <el-radio-group v-model="formFormatData.formData.balance.is_refund_examine ">
                <el-radio label="1">开启</el-radio>
                <el-radio label="2">关闭</el-radio>
              </el-radio-group>
            </el-form-item>
            <!-- <el-form-item label="退款比例" prop="balance.ride">

              <el-input-number :controls="false" :min="0" :precision='2' v-model="formFormatData.formData.balance.ride"></el-input-number>
            </el-form-item> -->
            <el-form-item label="充值套餐">
              <div style="margin-bottom:20px;" class="input-slot flex-row flex-align-c flex-justify-s wlm-input-appendbox envelope-input-number" v-for="(item, index) in formFormatData.formData.balance.meal" :key="index">
                <div class="wlm-input-append append-left">满</div>
                <el-input-number :controls="false" :min="0" v-model="item.balance"></el-input-number>
                <div class="wlm-input-append append-right">元</div>
                <div class="wlm-input-append append-left">送</div>
                <el-input-number :controls="false" :min="0" v-model="item.money"></el-input-number>
                <div class="wlm-input-append append-right">余额</div>
                <el-button style="margin-left:10px;" icon="el-icon-delete" circle plain @click="delMeal(index)"></el-button>
              </div>
              <el-button type="text" @click="addtc">添加套餐</el-button>
            </el-form-item>
            <el-form-item label="零余额是否显示支付">
              <el-radio-group v-model="formFormatData.formData.balance.zero_is_pay">
                <el-radio label="1">显示</el-radio>
                <el-radio label="2">不显示</el-radio>
              </el-radio-group>
            </el-form-item>
             <el-form-item label="余额提现">
              <el-radio-group v-model="formFormatData.formData.balance.withdrawal_open">
                <el-radio label="1">开启</el-radio>
                <el-radio label="2">关闭</el-radio>
              </el-radio-group>
            </el-form-item>
               <el-form-item label="提现手续费">
                   <div class="input-slot flex-row flex-align-c flex-justify-s wlm-input-appendbox envelope-input-number">
                <el-input-number :controls="false" v-model="formFormatData.formData.balance.withdrawal_sale"></el-input-number>
                <div class="wlm-input-append append-right">%</div>
              </div>
                 
            </el-form-item>
          </el-form>
        </div>
      </section>
    </div>
    <div class="wlm-form">
      <div class="wlm-form-hearder flex-row flex-justify-b">
        <span>积分设置</span>
      </div>
      <section>
        <div class="wlm-form-content">
          <el-form ref="qiniu" :model="formFormatData.formData.key" size="small" label-width="140px" class="retail-form" label-position="right">
            <el-form-item label="开启">
              <el-radio-group v-model="formFormatData.formData.integral.open">
                <el-radio label="2">关闭</el-radio>
                <el-radio label="1">开启</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="抵扣">
              <el-radio-group v-model="formFormatData.formData.integral.use">
                <el-radio label="2">关闭</el-radio>
                <el-radio label="1">开启</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="抵扣规则">
              <div class="input-slot flex-row flex-align-c flex-justify-s wlm-input-appendbox envelope-input-number">
                <div class="wlm-input-append append-left">1元 =</div>
                <el-input-number :controls="false" :min="0" v-model="formFormatData.formData.integral.rule"></el-input-number>
                <div class="wlm-input-append append-right">积分</div>
              </div>
            </el-form-item>
            <el-form-item label="默认最高抵扣" prop="bucket">
              <div class="input-slot flex-row flex-align-c flex-justify-s wlm-input-appendbox envelope-input-number">
                <el-input-number :controls="false" :min="0" v-model="formFormatData.formData.integral.default_max_money"></el-input-number>
                <div class="wlm-input-append append-right">元</div>
              </div>
            </el-form-item>
            <el-form-item label="文字定义">
              <el-input placeholder="积分" v-model="formFormatData.formData.integral.str">
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </section>
    </div>
    <div class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
      <el-button size="small" @click="formFormatSubmit" type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
import {
  balanceSave,
  getBalance
} from '@/api/setting'
import mixins from '@/mixins/mixins'
import { checkNumberAnddDecimal } from './../../utils/validate'
export default {
  mixins: [mixins.getters('Form')],
  name: 'PointBalance',
  components: {

  },
  directives: {

  },
  data() {
    return {
      formFormatData: {
        key: ['aliyun', 'qiniu'],
        api: {
          editForm: {
            api: getBalance,
            params: {
              always: true
            }
          },
          submitForm: balanceSave
        },
        formData: {
          balance: {
            open: '2',
            str: '',
            is_refund_balance: 1,
            is_refund_examine:2,
            ride: '',
            meal: [{ balance: '', money: '' }],
            zero_is_pay: '1',
            withdrawal_open:'2',
            withdrawal_sale:'',
          },
          integral: {
            open: '2',
            use: '2',
            rule: '',
            default_max_money: '',
            str: ''
          }
        },
        rules: {
          'balance.ride': { message: '不能小于0', validator: checkNumberAnddDecimal, trigger: 'blur' }
        }
      }
    }
  },
  methods: {
    addtc() {
      this.formFormatData.formData.balance.meal.push({ balance: '', money: '' })
    },
    delMeal(index) {
      this.formFormatData.formData.balance.meal.splice(index, 1)
    }
  }
}
</script>
